package com.example.toutiao.ui.main.adpater

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.toutiao.R
import com.example.toutiao.ui.main.model.MinVideoModel
import com.example.toutiao.utils.ImageLoaderUtils

class MinVideoAdapter(minVideoList:MutableList<MinVideoModel>):RecyclerView.Adapter<MinVideoAdapter.MinVideoHolder>() {
    private  var minVideoList:MutableList<MinVideoModel>?=minVideoList

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MinVideoHolder =MinVideoHolder(
        LayoutInflater.from(parent.context).inflate(R.layout.item_min_video,parent,false))

    override fun onBindViewHolder(holder: MinVideoHolder, position: Int) {
        if(minVideoList!=null){
            val mMinVideoModel:MinVideoModel= minVideoList!![position]
            ImageLoaderUtils.loadImage(holder.itemView.context,mMinVideoModel.videoImg,holder.mPhoto)
            holder.mNum.text="${mMinVideoModel.playNum}"
            holder.mLink.text="${mMinVideoModel.fabulousNum}"
            holder.mTitle.text="${mMinVideoModel.videoTitle}"
        }
    }

    override fun getItemCount(): Int =minVideoList!!.size
    class MinVideoHolder(it:View) :RecyclerView.ViewHolder(it){
        var mNum:TextView=it.findViewById(R.id.tv_video_num)
        var mLink:TextView=it.findViewById(R.id.tv_link_num)
        var mTitle:TextView=it.findViewById(R.id.tv_video_name)
        var mPhoto:ImageView=it.findViewById(R.id.iv_photo)
    }
}